---
hide_table_of_contents: true
sidebar_position: 3
sidebar_class_name: hidden
---

# Conversational

import CodeBlock from "@theme/CodeBlock";
import Example from "@examples/agents/chat_convo_with_tracing.ts";
import RunnableExample from "@examples/agents/chat_convo_with_tracing_runnable.ts";

This walkthrough demonstrates how to use an agent optimized for conversation. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may want the agent to be able to chat with the user as well.

This example shows how to construct an agent using LCEL. Constructing agents this way allows for customization beyond what previous methods like using `initializeAgentExecutorWithOptions` allow.

# Using LCEL

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/openai
```

<CodeBlock language="typescript">{RunnableExample}</CodeBlock>

# Using `initializeAgentExecutorWithOptions`

The example below covers how to create a conversational agent for a chat model. It will utilize chat specific prompts.

<CodeBlock language="typescript">{Example}</CodeBlock>

````
Loaded agent.
Entering new agent_executor chain...
{
    "action": "Final Answer",
    "action_input": "Hello Bob! How can I assist you today?"
}
Finished chain.
Got output Hello Bob! How can I assist you today?
Entering new agent_executor chain...
{
    "action": "Final Answer",
    "action_input": "Your name is Bob."
}
Finished chain.
Got output Your name is Bob.
Entering new agent_executor chain...
```json
{
    "action": "search",
    "action_input": "weather in pomfret"
}
```
A steady rain early...then remaining cloudy with a few showers. High 48F. Winds WNW at 10 to 15 mph. Chance of rain 80%.
```json
{
    "action": "Final Answer",
    "action_input": "The weather in Pomfret is a steady rain early...then remaining cloudy with a few showers. High 48F. Winds WNW at 10 to 15 mph. Chance of rain 80%."
}
```
Finished chain.
Got output The weather in Pomfret is a steady rain early...then remaining cloudy with a few showers. High 48F. Winds WNW at 10 to 15 mph. Chance of rain 80%.
````
